package com.yoomiito.app.adapter.goods.list.sort

import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.*
import com.yoomiito.app.model.gift.GiftGoods
import com.yoomiito.app.utils.*
import com.yoomiito.app.widget.CouponView

class ThemeTaoBaoAdapter(data: List<GiftGoods>?) : BaseQuickAdapter<GiftGoods, BaseViewHolder>(R.layout.item_goods, data) {

    override fun convert(helper: BaseViewHolder, item: GiftGoods) {
        ImageLoader.getInstance().into(mContext, item.imageUrl, helper.getView(R.id.item_goods_img),R.drawable.goods_default)

        helper.setText(R.id.goodsTitle, SpannableUtils.getIconAndText(item.title,ResUtil.getDrawable(DataUtils.ivType(item?.type))))

        helper?.getView<CouponView>(R.id.awardView).let{
            it.setText(item.buyAwardPrice)
            it.visibility = if (UserInfoConfig.getRoleId() < Type.LevelType.VIP_7||SpannableUtils.isEmptyOr0(item.buyAwardPrice)) View.GONE else View.VISIBLE
        }
       helper?.getView<CouponView>(R.id.couponView).let {
            if (SpannableUtils.isEmptyOr0(item.couponPrice)){
                it.setHeaderTextVisible(false)
                it.setText("特价精选" )
            }else{
                it.setHeaderTextVisible(true)
                it.setText("¥${item.couponPrice}" )
            }
        }

//        couponView.visibility = if(item.couponPrice.isEmptyOr0()) View.GONE else View.VISIBLE

        val priceT = item.discountPrice.removeDecimalPoint()
        val oldPriceT = item.zkFinalPrice.removeDecimalPoint()
        val price = if (oldPriceT.isEmptyOr0()||priceT==oldPriceT) "¥$priceT " else "¥$priceT ¥$oldPriceT"
        helper.setText(R.id.goodsPrice, price.goodsPrice(priceT))

        helper.setText(R.id.item_store_name, item.nick)
        helper.setText(R.id.item_sale_size, "月销" + item.salesNum.formatNum())
    }
}
